package com.zeei.bfs.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zeei.bfs.service.SessionService;
import com.zeei.common.controller.BasicController;
import com.zeei.common.vo.UserVO;

@Controller
@RequestMapping("/bfs/session")
public class SessionController extends BasicController {

	@Resource
	private SessionService sessionService;

	@RequestMapping(value = "/querySessionById", method = RequestMethod.POST)
	@ResponseBody
	public UserVO querySessionById(String sessionId) {
		UserVO userInfo = sessionService.querySessionById(sessionId);
		return userInfo;
	}

	@RequestMapping(value = "/updateExpiringDate", method = RequestMethod.POST)
	@ResponseBody
	public UserVO updateExpiringDate(String sessionId, String webSessionId) {
		UserVO userInfo = sessionService.querySessionById(sessionId);
		if (userInfo.getUserid() != null) {
			userInfo.setSessionId(sessionId);
			sessionService.updateExpiringDate(sessionId);
		} else {
			userInfo = sessionService.querySessionById(webSessionId);
			if (userInfo.getUserid() != null) {
				userInfo.setSessionId(webSessionId);
				sessionService.updateExpiringDate(webSessionId);
			}
		}
		return userInfo;
	}
}
